﻿Imports Negocio
Imports Servicios
Imports Excepciones

Public Class frmConsultaPerfil

    Protected Overrides Sub PreLoad()
        Me.Icon = Icon.FromHandle(Global.SIPRO.My.Resources.Resources.User_group.GetHicon())
    End Sub

    Private Sub btnNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNuevo.Click
        Dim f = New frmABMPerfil
        If f.ShowDialog = DialogResult.OK Then
            Init()
        End If
    End Sub

    Private Sub frmConsultaIdioma_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Init()
    End Sub

    Private Sub Init()
        Try
            Dim perfs As List(Of Perfil) = GesPerfiles.Consultar(Nothing)
            lbPerfiles.DataSource = perfs
            lbPerfiles.ValueMember = "OID"
            lbPerfiles.DisplayMember = "Nombre"
        Catch ex As Exception
            My.Application.HandlerException(ex)
            Me.Close()
        End Try
    End Sub

    Private Sub btnEliminar_Click(sender As System.Object, e As System.EventArgs) Handles btnEliminar.Click

        If lbPerfiles.Items.Count > 0 AndAlso TypeOf lbPerfiles.SelectedItem Is Perfil Then
            If MessageExt.Show(GesIdiomas.TraduceMensaje("MSGPF001").ToString, MessageBoxButtons.OKCancel) = DialogResult.OK Then
                Dim perf As New Perfil()
                perf = DirectCast(lbPerfiles.SelectedItem, Perfil)
                Try
                    GesPerfiles.Eliminar(perf)
                Catch ex As Exception
                    My.Application.HandlerException(ex)
                End Try
                Init()
            End If
        Else
            My.Application.HandlerException(New ItemSelectRequiredException())
        End If

    End Sub

    Private Sub Cancel_Click(sender As System.Object, e As System.EventArgs) Handles btnCerrar.Click
        Me.Close()
    End Sub

    Private Sub lbPerfiles_DoubleClick(sender As System.Object, e As System.EventArgs) Handles lbPerfiles.DoubleClick

        If lbPerfiles.Items.Count > 0 AndAlso TypeOf lbPerfiles.SelectedItem Is Perfil Then
            Dim f As New frmABMPerfil(DirectCast(lbPerfiles.SelectedItem, Perfil))
            If f.ShowDialog = DialogResult.OK Then
                Init()
            End If
        Else
            My.Application.HandlerException(New ItemSelectRequiredException())
        End If

    End Sub


End Class